package com.tjp.eight.ui.fragment.tabme;

import com.tjp.eight.AllRetrofit;
import com.tjp.eight.base.BasePresenterImpl;
import com.tjp.eight.constant.UrlConstant;
import com.tjp.eight.net.NetCallBack;
import com.tjp.eight.net.SubscribeCallBack;
import com.tjp.eight.utils.AppUtils;

import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/2/13.
 */
public class MePresenter extends BasePresenterImpl<MeView> {
    private MeService service = AllRetrofit.getRetrofit(UrlConstant.BaseUrl).create(MeService.class);

    public MePresenter(MeView meView) {
        attachView(meView);
    }

    public void sign(String signJson) {
        RequestBody rq = AppUtils.getRequestBody(signJson);
        addSubscription(service.sign(rq), new SubscribeCallBack<>(new NetCallBack<SigneRModel>() {
            @Override
            public void onSuccess(SigneRModel model) {
                view.signSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    public void loadData(String pJson) {
        RequestBody rq = AppUtils.getRequestBody(pJson);
        addSubscription(service.loadData(rq), new SubscribeCallBack<>(new NetCallBack<MeModel>() {
            @Override
            public void onSuccess(MeModel model) {
                view.loadSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }
}
